<?php
class Invoice extends DB
{
    var $_table = 'invoice';

    function get($id)
    {
	if ( is_numeric($id) )
	{
	    $this->_id = $id;

	    $query = sprintf('SELECT * FROM `%s` WHERE `id`=%d LIMIT 1',$this->_table,$id);

	    if ( $result = $this->_doQuery($query) )
	    {
		if ( $this->_obj = mysql_fetch_assoc($result) )
		{
		    $query = sprintf('SELECT * FROM `invoice_items` WHERE `invoice_id`=%d',$this->_obj['id']);

		    if ( $result = $this->_doQuery($query) )
		    {
			while ( $row = mysql_fetch_assoc($result) )
			{
			    $this->_obj['_item'][] = $row;
			}
		    }

		    return $this->_obj;
		}
	    }
	}
    }

    function make($account_id)
    {
	if ( is_numeric($account_id) )
	{
	    $this->_doQuery(sprintf('INSERT INTO `invoice_create_queue` (`account_id`,`create_date`) VALUES (%d,NOW())',$account_id));
	    return true;
	}
    }
}

class InvoiceQueue extends DB
{
    var $_table = 'invoice_create_queue';
}
?>
